package com.ruoyi.web.controller.goods;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.goods.domain.Shangpinxinxi;
import com.ruoyi.goods.service.IShangpinxinxiService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品信息Controller
 *
 * @author ruoyi
 * @date 2023-05-18
 */
@Api(tags="商品信息管理")
@RestController
@RequestMapping("/system/shangpinxinxi")
public class ShangpinxinxiController extends BaseController
{
    @Autowired
    private IShangpinxinxiService shangpinxinxiService;

    /**
     * 查询商品信息列表
     */
    @ApiOperation("查询商品信息")
    @PreAuthorize("@ss.hasPermi('system:shangpinxinxi:list')")
    @GetMapping("/list")
    public TableDataInfo list(Shangpinxinxi shangpinxinxi)
    {
        startPage();
        List<Shangpinxinxi> list = shangpinxinxiService.selectShangpinxinxiList(shangpinxinxi);
        return getDataTable(list);
    }

    /**
     * 导出商品信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:shangpinxinxi:export')")
    @Log(title = "商品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Shangpinxinxi shangpinxinxi)
    {
        List<Shangpinxinxi> list = shangpinxinxiService.selectShangpinxinxiList(shangpinxinxi);
        ExcelUtil<Shangpinxinxi> util = new ExcelUtil<Shangpinxinxi>(Shangpinxinxi.class);
        util.exportExcel(response, list, "商品信息数据");
    }

    /**
     * 获取商品信息详细信息
     */
    @ApiOperation("查询商品详细信息")
    @PreAuthorize("@ss.hasPermi('system:shangpinxinxi:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shangpinxinxiService.selectShangpinxinxiById(id));
    }

    /**
     * 新增商品信息
     */
    @ApiOperation("新增商品信息")
    @PreAuthorize("@ss.hasPermi('system:shangpinxinxi:add')")
    @Log(title = "商品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Shangpinxinxi shangpinxinxi)
    {
        return toAjax(shangpinxinxiService.insertShangpinxinxi(shangpinxinxi));
    }

    /**
     * 修改商品信息
     */
    @ApiOperation("修改商品信息")
    @PreAuthorize("@ss.hasPermi('system:shangpinxinxi:edit')")
    @Log(title = "商品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Shangpinxinxi shangpinxinxi)
    {
        return toAjax(shangpinxinxiService.updateShangpinxinxi(shangpinxinxi));
    }

    /**
     * 删除商品信息
     */
    @ApiOperation("删除商品信息")
    @PreAuthorize("@ss.hasPermi('system:shangpinxinxi:remove')")
    @Log(title = "商品信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shangpinxinxiService.deleteShangpinxinxiByIds(ids));
    }
}
